﻿
if not exists(select * from sysobjects where name = 'Cart' and xtype = 'U')
Begin

CREATE TABLE [dbo].[Cart](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreationDate] [datetime] NOT NULL,
	[VisitorId] [nvarchar](40) NOT NULL,
	[CartStateId] [int] NOT NULL,
	[CustomerId] [int] NULL,
	[CustomerPersonId] [int] NULL,
	[Message] [nvarchar](max) NULL,
	[AllowPartialDelivery] [bit] NOT NULL,
	[IsPresent] [bit] NOT NULL,
	[CustomerDocumentReference] [nvarchar](100) NULL,
	[LastUpdate] [datetime] NOT NULL,
	[Code] [varchar](40) NOT NULL,
	[DeliveryAddressId] [int] NULL,
	[ShippingFeeAmount] [bigint] NULL,
	[ShippingFeeTaxRate] [int] NULL,
	[ConvertedEntityId] [int] NULL,
	[ConversionDate] [datetime] NULL,
	[ConveyorId] [int] NULL,
	[QuoteCorporateName] [nvarchar](80) NULL,
	[QuoteCountryId] [int] NULL,
	[QuoteEmail] [nvarchar](50) NULL,
	[QuoteFaxNumber] [nvarchar](15) NULL,
	[QuotePhoneNumber] [nvarchar](15) NULL,
	[QuoteFirstName] [nvarchar](25) NULL,
	[QuoteLastName] [nvarchar](25) NULL,
	[QuotePresentationId] [int] NULL,
	[QuoteZipCode] [varchar](10) NULL,
	[AcceptTermsAndConditions] [bit] NOT NULL,
	[CouponCode] [varchar](50) NULL,
	[LastPage] [nvarchar](255) NULL,
	[FromEntityId] [int] NULL,
	[FromMetaEntityId] [int] NULL,
	[PaymentModeName] [varchar](50) NULL,
	[LeadSourceName] [varchar](512) NULL,
	[LeadSourceId] [varchar](50) NULL,
	[DiscountTotal] [bigint] NOT NULL,
	[DiscountTotalTaxRate] [int] NOT NULL,
	[RevisionId] [timestamp] NOT NULL,
	[ShippingFeeLocked] [bit] NOT NULL,
	[MessageForConveyor] [varchar](max) NULL,
)

alter table Cart add constraint PK_Cart_Id primary key (Id)

create unique index IX_Cart_Code on Cart(code)

create index IX_Cart_VisitorId on Cart(VisitorId)

End
Go